public class ThreadStates {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    System.out.println(Thread.currentThread().getName()+","+i);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }
            }
        };
        Thread thread = new Thread(runnable);
        System.out.println("step1："+thread.getState());
        thread.start();
        System.out.println("step2："+thread.getState());

        while (Thread.State.TERMINATED!=thread.getState()){
            System.out.println("step3："+thread.getState());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e){
                throw new RuntimeException(e);
            }
        }
        System.out.println("step4："+thread.getState());

    }
}
